var express = require('express');
var router = express.Router();

/* GET login. */
router.get('/', function (req, res, next) {
    res.render('login', {title: "登录"});
}).post(function (req, res) {
    var User = global.dbHandal.getModel('user');
    var uuname = req.body.uuname;
    User.findOne({name: uuname}, function (err, doc) {
        if (err) {
            res.send(500);
            console.log(err);
        } else if (!doc) {
            req.session.error = '用户名不存在';
            res.send(400);
        } else {
            req.session.user = doc;
            res.send(200);
        }
    })

});

module.exports = router;
